﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using InterfacesTransformation;

namespace MyWordSegmentorJSharp
{
    public partial class JSharpWordSegmentorPlugin : UserControl, IWordSegmentor
    {
        public JSharpWordSegmentorPlugin()
        {
            InitializeComponent();
        }

        private IHost pluginHost = null;
        public IHost PluginHost
        {
            get
            {
                return pluginHost;
            }
            set
            {
                this.pluginHost = value;
            }
        }

        private string pluginName = "Vietnamese Word Segmentor In JSharp";
        public string PluginName
        {
            get
            {
                return this.pluginName;
            }
        }

        private string pluginDescription = "Segment vietnamese sentences or phrases into words.";

        public string PluginDescription
        {
            get { return pluginDescription; }
            set { pluginDescription = value; }
        }

        public UserControl PluginUserControl
        {
            get
            {
                return this;
            }
        }

        public void Initialize()
        {
        }

        public void PluginDispose()
        {

        }

        #region Interfaces Implementation
        public string Segment(string inputStr)
        {
            // get folder path này từ user control của plugin này
            string folderOfDictionaryData = this.textBoxDictionaryPath.Text;
            return SegmentString(inputStr, folderOfDictionaryData);
        }

        public List<string> Segment(List<string> inputStrList)
        {
            string folderOfDictionaryData = this.textBoxDictionaryPath.Text;
            KWCollector kwCollector = new KWCollector(folderOfDictionaryData);
            List<string> result = new List<string>();
            foreach (string curStr in inputStrList)
            {
                result.Add(kwCollector.ConvertToVNSentence(curStr));
            }
            return result;
        }
        #endregion

        #region Fix Functions
        private string SegmentString(string inputStr, string folderOfDictionaryData)
        {
            KWCollector kwCollector = new KWCollector(folderOfDictionaryData);
            string parsedStr = kwCollector.ConvertToVNSentence(inputStr);
            return parsedStr;
        }
        #endregion

        #region GUI Event Handlers
        private void buttonBrowse_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog myFolderBrowserDlg = new FolderBrowserDialog();
            myFolderBrowserDlg.Description = "Select the dictionary folder";
            if (myFolderBrowserDlg.ShowDialog() == DialogResult.OK)
            {
                textBoxDictionaryPath.Text = string.Empty;
                textBoxDictionaryPath.Text = myFolderBrowserDlg.SelectedPath;
            }
        }
        #endregion
    }
}
